//默认导出 export default render 一个文件中默认导出只能导出一次
//引用时import render from './render'，引入的变量名可以重命名

//命名导出export 引用时 import {render} from './render'
//一个文件可以导出多个

export const render = (element,container)=>{
  const {type,props} = element; //解构
  //创建元素
  const ele = document.createElement(type);
  //遍历属性
  Object.keys(props).forEach( attr =>{
    if(attr == 'children'){
      const child = props['children'];
      if(typeof props['children'] == 'string'){
        ele.innerText = props['children']
      } else if(child instanceof Array){
        child.forEach(elem=>{
          render(child,ele)
        })
      } else {
        render(child,ele)
      }
    } else {
      ele[attr] = props[attr]
    }
  })
  //容器中添加元素
  container.appendChild(ele)
}
